package com.hzdl.cinema.dao.impl;

import com.hzdl.cinema.dao.SearchSeatDao;
import com.hzdl.cinema.domain.Play;
import com.hzdl.cinema.domain.Ticket;
import com.hzdl.cinema.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class SearchSeatDaoImpl implements SearchSeatDao {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());



    //确认购票
    @Override
    public void confirm(int userId, String ticketId) {
        String s = "update ticket set ticket_Status =1 ,user_Id=? where ticket_Id=?";
        jdbcTemplate.update(s,userId,ticketId);
    }

//买票
    @Override
    public  List<Ticket> buyTickets(String playName) {
        String s="select * from ticket where schedule_Id=(SELECT schedule_Id from schedule where play_Id=" +
                "(select play_Id from play where play_Name=?))";
        List<Ticket> ticketList = jdbcTemplate.query(s, new BeanPropertyRowMapper<>(Ticket.class),playName);
        return ticketList;
    }

    @Override
    public Play findPlay(String playName) {
        String s="select * from play where play_Name=?";
        Play play = jdbcTemplate.queryForObject(s, new BeanPropertyRowMapper<>(Play.class),playName);
        return play;
    }
}
